(function () {

	//获取项目合同细目泵数据 服务器分页
    var contractPumpData = {};
    contractPumpData.contractId=jQuery('#contractId').val();
    var serverPumpTable;
    jQuery(document).ready(function () {
    	serverPumpTable = jQuery('#resultPumpTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/contract/getDevice',
                "data": function (d) {
                    return $.extend({}, d, contractPumpData);
                }
            },
            columns: [
                {
                	data: null
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildPump">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'productName'
                },
                {
                    data: 'productType'
                },
                {
                    data: 'subDivideType'
                },
                {
                	data: 'productModel'
                },
                {
                    data: 'number'
                },
                {
                    data: 'unitPrice'
                },
                {
                    data: 'power'
                },
                {
                    data: 'flowMaterial'
                },
                {
                    data: 'transMedia'
                },
                {
                    data: 'viscosity'
                },
                {
                    data: 'flux'
                },
                {
                    data: 'pumpLift'
                },
                {
                    data: 'temperature'
                },
                {
                    data: 'proportion'
                },
                {
                    data: 'inPressure'
                },
                {
                    data: 'effectiveNPSHA'
                },
                {
                    data: 'mustMPSHA'
                },
                {
                    data: 'nBillType',
                    	render: function (data, type, full, meta) {
                     	var dOut;
                     	 if(data==0){
                     		dOut = '<td class="center" >自制件</td>';
                     	}
                     	else if(data==1){
                     		dOut = '<td class="center" >外购件</td>';
                     	}
     	            	return dOut;
                     }
                },
                {
                    data: 'cMotor',
                    render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 18) ? '<font title="'+data+'">'+data.substring(0,18)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'cAttachment',
                    render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 18) ? '<font title="'+data+'">'+data.substring(0,18)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'cSysPump'
                },
                {
                    data: 'cPumpType'
                },
                {
                    data: 'nPumpNum'
                },
                {
                    data: 'nPumpTotalPrice'
                },
                {
                    data: 'dDeliveryDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY-MM-DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'nIsSpecial',
                	render: function (data, type, full, meta) {
                     	var aOut;
                     	 if(data==0){
                     		aOut = '<td class="center" >是</td>';
                     	}
                     	else if(data==1){
                     		aOut = '<td class="center" >否</td>';
                     	}
     	            	return aOut;
                     }
                },
                {
                    data: 'cStructure'
                },
                {
                    data: 'cOutletPressure'
                },
                {
                    data: 'cBitNumber'
                },
                {
                    data: 'cUnit'
                },
                {
                    data: 'cMemo',
                    render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 18) ? '<font title="'+data+'">'+data.substring(0,18)+'...'+'</font>' : data;
						}
					}
                }],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    	
    	//删除项目合同细目泵
    	jQuery('.delPumpBtn').on('click', function () {
    		   var selects=getSelect("#resultPumpTable",1);
    		   var url=window.rootPath+"/ui/contract/deleteDevice";
    		   var contractId = jQuery("#contractId").val(); 
    		   var totalSum = jQuery("#totalSum").val();
    		   $("#checkAllPump").prop("checked", false);
    		   delSelect(selects,url,serverPumpTable);
    		   var urlxy = window.rootPath + '/ui/contract/checkMoney?contractId=' + contractId + '&totalSum=' + totalSum;
    		   jQuery.ajax({
               	type : 'get',
               	url : encodeURI(urlxy),
               	dataType : 'json',
               	contentType : 'application/json;charset=utf-8',
               	success : function(data) {
               		if(data==0){
               			alert("合同金额与细目的总金额相同！");
               		} else if(data==1){
               			alert("合同金额小于细目的总金额！");
               		} else if(data==2){
               			alert("合同金额大于细目的总金额！");
               		}
               	}
               });
    		});
    	
    	//泵添加按钮
		jQuery('.addPumpBtn').on("click", function() {
			var contractId = jQuery('#contractId').val();
        	if(contractId == ""){
            	if (confirm("当前合同还未保存，是否保存？")) {
            		saveContract('addPumpBtn');
            	}
            }else{
            	showDeviceModal();
            }
		});
		
		//编辑泵
		jQuery(".editPumpBtn").on('click', function() {
			var selects = getSelect("#resultPumpTable", 1);
			if (selects.length > 1) {
				$.springLemonDialog({
					content : '一次只能编辑一条记录',// 确认文本
					clickButton : function(sender, modal, index) {// 按钮事件处理
						$(this).closeDialog(modal);
					}
				});
			} else if (selects.length == 0) {
				$.springLemonDialog({
					content : '请选择要编辑的记录',// 确认文本
					clickButton : function(sender, modal, index) {// 按钮事件处理
						$(this).closeDialog(modal);
					}
				});
			} else if (selects.length == 1) {
				var id = selects[0].id;
				jQuery("#mainDeviceId").val(id);
				jQuery("#maincreateTime").val(selects[0].createTime);
				jQuery("#productName").val(selects[0].productName);
				jQuery("#productType").val(selects[0].productType);
				jQuery("#subDivideType").empty();
				var url=window.rootPath+"/ui/contract/getDeviceOption/"+selects[0].productType;
        		jQuery.ajax({
        			url:  encodeURI(url),
        			cache:false,
                    type: 'get',
                    dataType: 'json',
                    success: function (data) {
                    	var options = data.options;
                    	for (var i=0; i<options.length; i++ ) 
                    	{ 
                    		var option = $("<option>").text(options[i]).val(options[i])
                    	    jQuery("#subDivideType").append(option);
                    	}
                    	jQuery("#subDivideType").val(selects[0].subDivideType);
                		jQuery("#productModel").val(selects[0].productModel);
        				jQuery("#number").val(selects[0].number);
        				jQuery("#unitPrice").val(selects[0].unitPrice);
        				jQuery("#power").val(selects[0].power);
        				jQuery("#viscosity").val(selects[0].viscosity);
        				jQuery("#flowMaterial").val(selects[0].flowMaterial);
        				jQuery("#transMedia").val(selects[0].transMedia);
        				jQuery("#proportion").val(selects[0].proportion);
        				jQuery("#NPSHA").val(selects[0].effectiveNPSHA);
        				jQuery("#flux").val(selects[0].flux);
        				jQuery("#temperature").val(selects[0].temperature);
        				jQuery("#MPSHA").val(selects[0].mustMPSHA);
        				jQuery("#pumpLift").val(selects[0].pumpLift);
        				jQuery("#inPressure").val(selects[0].inPressure);
        				if(selects[0].nBillType == 0){
        					jQuery("#BillType").val("自制件");
        				}else{
        					jQuery("#BillType").val("外购件");
        				}
        				
        				jQuery("#Motor").val(selects[0].cMotor);
        				jQuery("#Attachment").val(selects[0].cAttachment);
        				jQuery("#SysPump").val(selects[0].cSysPump);
        				jQuery("#PumpType").val(selects[0].cPumpType);
        				jQuery("#PumpNum").val(selects[0].nPumpNum);
        				jQuery("#PumpTotalPrice").val(selects[0].nPumpTotalPrice);
        				if(selects[0].dDeliveryDate != null && selects[0].dDeliveryDate　!= ""){
        					jQuery("#dDeliveryDate").val(moment(selects[0].dDeliveryDate).format('YYYY-MM-DD'));
        				}else{
        					jQuery("#dDeliveryDate").val("");
        				}
        				//jQuery("#nIsSpecial").val(selects[0].nIsSpecial);
        				if(selects[0].nIsSpecial == 0){
        					jQuery("#IsSpecial").val("是");
        				}else{
        					jQuery("#IsSpecial").val("否");
        				}
        				jQuery("#Structure").val(selects[0].cStructure);
        				jQuery("#OutletPressure").val(selects[0].cOutletPressure);
        				jQuery("#BitNumber").val(selects[0].cBitNumber);
        				jQuery("#Unit").val(selects[0].cUnit);
        				jQuery("#cMemo").val(selects[0].cMemo);
        				jQuery("#mainDeviceModal").modal('show');
                    }
        		});
			}
		});
		
		///下拉框产品类型改变////
		jQuery('#productType').trigger('change');///自动触发下拉框
		
		jQuery('#productType').change(function(){
			var productType = jQuery("#productType").val();
			jQuery("#subDivideType").empty();
			var url=window.rootPath+"/ui/contract/getDeviceOption/"+productType;
    		jQuery.ajax({
    			url:  encodeURI(url),
    			cache:false,
                type: 'get',
                dataType: 'json',
                success: function (data) {
                	var options = data.options;
                	for (var i=0; i<options.length; i++ ) 
                	{ 
                		var option = $("<option>").text(options[i]).val(options[i])
                	    jQuery("#subDivideType").append(option);
                	}
                }
    		})
		});
		
		//新建/编辑单个泵保存
		jQuery(".savePumpBtn").on("click", function() {
			if (jQuery("#mainDeviceForm") && !jQuery("#mainDeviceForm").Validform({
				tiptype : 3,
				showAllError : true
			}).check(false)) {
				return;
			}
			jQuery(".savePumpBtn").attr("disabled", true);
			var url = window.rootPath + '/ui/contract/editOneDevice';
			var totalSum = jQuery("#totalSum").val();
			var id = jQuery("#mainDeviceId").val();
			var createTime = jQuery("#maincreateTime").val();
			var productName = jQuery("#productName").val();
			var subDivideType = jQuery("#subDivideType").val();
			var productType = jQuery("#productType").val();
			var productModel = jQuery("#productModel").val();
			var number = jQuery("#number").val();
			var unitPrice = jQuery("#unitPrice").val();
			var power = jQuery("#power").val();
			var flowMaterial = jQuery("#flowMaterial").val();
			var transMedia = jQuery("#transMedia").val();
			var viscosity = jQuery("#viscosity").val();
			var flux = jQuery("#flux").val();
			var pumpLift = jQuery("#pumpLift").val();
			var temprature = jQuery("#temperature").val();
			var proportion = jQuery("#proportion").val();
			var inPressure = jQuery("#inPressure").val();
			var NPSHA = jQuery("#NPSHA").val();
			var MPSHA = jQuery("#MPSHA").val();
			var contractId = jQuery("#contractId").val();
			var illType = jQuery("#BillType").val();
			var BillType = 0;
			if(illType == "自制件"){
				BillType = 0;
			}else{
				BillType = 1
			}
			var Motor = jQuery("#Motor").val();
			var Attachment = jQuery("#Attachment").val();
			var SysPump = jQuery("#SysPump").val();
			var PumpType = jQuery("#PumpType").val();
			var PumpNum = jQuery("#PumpNum").val();
			var PumpTotalPrice = jQuery("#PumpTotalPrice").val();
			var dDeliveryDate = jQuery("#dDeliveryDate").val();
			var IsSpeci = jQuery("#IsSpecial").val();
			var IsSpecial;
			if(IsSpeci == "是"){
				IsSpecial = 0;
			}else{
				IsSpecial = 1;
			}
			var Structure = jQuery("#Structure").val();
			var OutletPressure = jQuery("#OutletPressure").val();
			var BitNumber = jQuery("#BitNumber").val();
			var Unit = jQuery("#Unit").val();
			var cMemo = jQuery("#cMemo").val();
			var contractType = "项目合同";
			if (id == '') {
				var d = {
					"productName" : productName,
					"productType" : productType,
					"subDivideType" : subDivideType,
					"productModel" : productModel,
					"number" : number,
					"unitPrice" : unitPrice,
					"power" : power,
					"flowMaterial" : flowMaterial,
					"transMedia" : transMedia,
					"viscosity" : viscosity,
					"flux" : flux,
					"pumpLift" : pumpLift,
					"temperature" : temprature,
					"proportion" : proportion,
					"inPressure" : inPressure,
					"effectiveNPSHA" : NPSHA,
					"mustMPSHA" : MPSHA,
					"contractType":contractType,
					"contractID" : contractId,
					"nBillType" : BillType,
					"cMotor" : Motor,
					"cAttachment" : Attachment,
					"cSysPump" : SysPump,
					"cPumpType" : PumpType,
					"nPumpNum" : PumpNum,
					"nPumpTotalPrice" : PumpTotalPrice,
					"dDeliveryDate" : dDeliveryDate,
					"nIsSpecial" : IsSpecial,
					"cStructure" : Structure,
					"cOutletPressure" : OutletPressure,
					"cBitNumber" : BitNumber,
					"cUnit" : Unit,
					"cMemo" : cMemo
				};
			} else {
				var d = {
					"id" : id,
					"createTime" : createTime,
					"productName" : productName,
					"productType" : productType,
					"subDivideType" : subDivideType,
					"productModel" : productModel,
					"number" : number,
					"unitPrice" : unitPrice,
					"power" : power,
					"flowMaterial" : flowMaterial,
					"transMedia" : transMedia,
					"viscosity" : viscosity,
					"flux" : flux,
					"pumpLift" : pumpLift,
					"temperature" : temprature,
					"proportion" : proportion,
					"inPressure" : inPressure,
					"effectiveNPSHA" : NPSHA,
					"mustMPSHA" : MPSHA,
					"contractType":contractType,
					"contractID" : contractId,
					"nBillType" : BillType,
					"cMotor" : Motor,
					"cAttachment" : Attachment,
					"cSysPump" : SysPump,
					"cPumpType" : PumpType,
					"nPumpNum" : PumpNum,
					"nPumpTotalPrice" : PumpTotalPrice,
					"dDeliveryDate" : dDeliveryDate,
					"nIsSpecial" : IsSpecial,
					"cStructure" : Structure,
					"cOutletPressure" : OutletPressure,
					"cBitNumber" : BitNumber,
					"cUnit" : Unit,
					"cMemo" : cMemo
					
				};
			}
			var urlxy = window.rootPath + '/ui/contract/checkMoney?contractId=' + contractId + '&totalSum=' + totalSum;
			jQuery.ajax({
				type : 'post',
				url : encodeURI(url),
				data : JSON.stringify(d),
				dataType : 'json',
				contentType : 'application/json;charset=utf-8',
				success : function(data) {
					jQuery("#mainDeviceModal").modal('hide');
					contractPumpData.contractId=jQuery('#contractId').val();
					serverPumpTable.draw(true);
					jQuery(".savePumpBtn").attr("disabled", false);
					jQuery.ajax({
						type : 'get',
						url : encodeURI(urlxy),
						dataType : 'json',
						contentType : 'application/json;charset=utf-8',
						success : function(data) {
							if(data==0){
								alert("合同金额与细目的总金额相同！");
							} else if(data==1){
								alert("合同金额小于细目的总金额！");
							} else if(data==2){
								alert("合同金额大于细目的总金额！");
							}
						}
					});
				}
			});
			
		});
		
    	//EXCEL导入
        jQuery('.importPumpList').on("click",function()
        {
        	var contractId = jQuery('#contractId').val();
        	var type = '1';
        	if(contractId == ""){
            	if (confirm("当前合同还未保存，是否保存？")) {
            		saveContract('importPumpList');
            	}
            }else{
            	fileUpload(contractId, type);
            }
        });
        
        /**
    	 * 保存项目合同
    	 */
        var saveContract = function(state) {
        	var signedDate = jQuery('#signedDate').val();
         	var scheduleDate = jQuery('#scheduleDate').val();
         	var giveOutDate = jQuery('#giveOutDate').val();
     		var operatDate = jQuery('#operatDate').val();
     		if (signedDate==""||scheduleDate==""||giveOutDate==""||operatDate==""){
     			message("请将页面上所有日期信息完善，保存后还可进行编辑。");
     			return ;
     		}
      	    var isId=jQuery("#contractId").val();
      	    var contractcreateTime=jQuery("#createTime").val();
    	    var createTime=new Date(contractcreateTime).getTime();
      	    var supplierCode = jQuery('#supplierCode').val();
      		var demanderCode = jQuery('#demanderCode').val();
      		var contractType = jQuery('#contractType').val();
      		var totalSum = jQuery('#totalSum').val();
      		var stop = jQuery('#stop').val();
      		var freightCharge = jQuery('#freightCharge').val();
      		var projectName = jQuery('#projectName').val();
      	 	var payType = jQuery('#payType').val();
      	 	var guaranteePeriod = jQuery('#guaranteePeriod').val();
      	 	var breakDuty = jQuery('#breakDuty').val();
      	 	var customerId = jQuery("#customerId").val();
      		var orderUnit = jQuery('#orderUnit').val();
      	 	var orderDelegate = jQuery('#orderDelegate').val();
      		var orderPhone = jQuery('#orderPhone').val();
      		var industryInfo = jQuery('#industryInfo').val();
      		var orderAddress = jQuery('#orderAddress').val();
      		var orderZip = jQuery('#orderZip').val();
      		var orderArea = jQuery('#orderArea').val();
      		var invoiceBank = jQuery("#invoiceBank").val();
      		var bankAccount = jQuery("#bankAccount").val();
      		var taxNumber = jQuery("#taxNumber").val();
      		var invoiceAddress = jQuery("#invoiceAddress").val();
      		var postUnit = jQuery('#postUnit').val();
      	 	var postDelegate = jQuery('#postDelegate').val();
      		var postPhone = jQuery('#postPhone').val();
      		var postAddress = jQuery('#postAddress').val();
      		var postZip = jQuery('#postZip').val();
      		var dutyArea = jQuery('#dutyArea').val();
      		var dutyOfficer = jQuery('#dutyOfficer').val();
      		var southNorthArea = jQuery('#southNorthArea').val();
      		var belongArea = jQuery('#belongArea').val();
      		var checkKind = jQuery('#checkKind').val();
      		var productKind = jQuery('#productKind').val();
      		var signOfficer = jQuery('#signOfficer').val();
      		var repairOfficer = jQuery('#repairOfficer').val();
      		var quotationOfficer = jQuery('#quotationOfficer').val();
      		var operatDepartment = jQuery('#operatDepartment').val();
      		var operator = jQuery('#operator').val();
      		var memo = jQuery('#memo').val();
      		var state = jQuery('#state').val();
      		var cstate = jQuery('#cstate').val();
      		if(isId == ""){// 新增合同
	      		var d = {
	     				"user":{"id":$("#userId").val()},
	                	"supplierCode": supplierCode,
	                	"demanderCode": demanderCode,
	                	"contractType": contractType,
	                    "totalSum": totalSum,
	                    "signedDate": signedDate,
	                    "scheduleDate": scheduleDate,
	                    "giveOutDate": giveOutDate,
	                    "stop": stop,
	                    "freightCharge": freightCharge,
	                    "projectName": projectName,
	                    "payType": payType,
	                    "guaranteePeriod": guaranteePeriod,
	                    "breakDuty": breakDuty,
	                    "customerId": customerId,
	                    "orderUnit": orderUnit,
	                    "orderDelegate": orderDelegate,
	                    "orderPhone": orderPhone,
	                    "industryInfo": industryInfo,
	                    "orderAddress": orderAddress,
	                    "orderZip": orderZip,
	                    "orderArea": orderArea,
	                    "invoiceBank": invoiceBank,
      	                "bankAccount": bankAccount,
      	                "taxNumber": taxNumber,
      	                "invoiceAddress": invoiceAddress,
	                    "postUnit": postUnit,
	                    "postDelegate": postDelegate,
	                    "postPhone": postPhone,
	                    "postAddress": postAddress,
	                    "postZip": postZip,
	                    "dutyArea": dutyArea,
	                    "dutyOfficer": dutyOfficer,
	                    "southNorthArea": southNorthArea,
	                    "belongArea": belongArea,
	                    "checkKind": checkKind,
	                    "productKind": productKind,
	                    "signOfficer": signOfficer,
	                    "repairOfficer": repairOfficer,
	                    "quotationOfficer": quotationOfficer,
	                    "operatDepartment": operatDepartment,
	                    "operator": operator,
	                    "operatDate": operatDate,
	                    "memo": memo,
	                    "state": state,
	                    "cstate": cstate,
	            };
      		}else{
      			var d = {
      					"id": isId,
  	        			"createTime": createTime,
	                	"supplierCode": supplierCode,
	                	"demanderCode": demanderCode,
	                	"contractType": contractType,
	                    "totalSum": totalSum,
	                    "signedDate": signedDate,
	                    "scheduleDate": scheduleDate,
	                    "giveOutDate": giveOutDate,
	                    "stop": stop,
	                    "freightCharge": freightCharge,
	                    "projectName": projectName,
	                    "payType": payType,
	                    "guaranteePeriod": guaranteePeriod,
	                    "breakDuty": breakDuty,
	                    "customerId": customerId,
	                    "orderUnit": orderUnit,
	                    "orderDelegate": orderDelegate,
	                    "orderPhone": orderPhone,
	                    "industryInfo": industryInfo,
	                    "orderAddress": orderAddress,
	                    "orderZip": orderZip,
	                    "orderArea": orderArea,
	                    "invoiceBank": invoiceBank,
      	                "bankAccount": bankAccount,
      	                "taxNumber": taxNumber,
      	                "invoiceAddress": invoiceAddress,
	                    "postUnit": postUnit,
	                    "postDelegate": postDelegate,
	                    "postPhone": postPhone,
	                    "postAddress": postAddress,
	                    "postZip": postZip,
	                    "dutyArea": dutyArea,
	                    "dutyOfficer": dutyOfficer,
	                    "southNorthArea": southNorthArea,
	                    "belongArea": belongArea,
	                    "checkKind": checkKind,
	                    "productKind": productKind,
	                    "signOfficer": signOfficer,
	                    "repairOfficer": repairOfficer,
	                    "quotationOfficer": quotationOfficer,
	                    "operatDepartment": operatDepartment,
	                    "operator": operator,
	                    "operatDate": operatDate,
	                    "memo": memo,
	                    "state": state,
	                    "cstate": cstate,
	            };
      		}
      		jQuery(".addPumpBtn").attr("disabled", true);
      		jQuery(".importPumpList").attr("disabled", true);
      		jQuery(".addOtherBtn").attr("disabled", true);
      		jQuery(".importOtherList").attr("disabled", true);
      		var id=isId;
      		if (id==null||id==''){
      			id = 'null';
      		}
      		if (cstate=="已完成"){
      			$.springLemonDialog({
  					content : '该合同已经生产商品计划，不能保存！',// 确认文本
  					clickButton : function(sender, modal, index) {// 按钮事件处理
  						$(this).closeDialog(modal);
  					}
      			});
  			}
      		if(cstate=="已排产"){
      			alert("保存合同后将修改排产相关信息。");
      		}
      		if (supplierCode!=''){// 验证供方合同号是否已存在
      			var urlValid=window.rootPath+"/ui/contract/validSupplierCode/"+id+"/"+supplierCode;
      	    	jQuery.ajax({
      	            url:encodeURI(urlValid),
      	            cache:false,
      	            type :"get",
      	            dataType:"json",
      	            contentType:"application/json;charset=utf-8",// 解决返回数据中的中文乱码问题
      	            success:function(data){
      	            	if(data.codeState==1){
      	            		$.springLemonDialog({
     		      		         content: '供方合同号已存在，请修改！',// 确认文本
     		      		         clickButton: function (sender, modal, index) {// 按钮事件处理
     		      		             $(this).closeDialog(modal);
     		      		         }
     		            		});
      	            		jQuery(".addPumpBtn").attr("disabled", false);
      	            		jQuery(".importPumpList").attr("disabled", false);
      	            		jQuery(".addOtherBtn").attr("disabled", false);
      	            		jQuery(".importOtherList").attr("disabled", false);
      	            		return;
      	            	}
      	                    var url = window.rootPath + "/ui/contract/saveContract";
      	                    jQuery.ajax({
      	                        type: 'post',
      	                        url: url,
      	                        data: JSON.stringify(d),
      	                        dataType: 'json',
      	                        contentType: 'application/json;charset=utf-8',
      	                        success: function (data) {
      	                        	var contractId = data.contractId;
      	                        	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
      	                        	jQuery("#createTime").val(time);
      	                        	jQuery("#contractId").val(contractId);
      	                        	jQuery(".addPumpBtn").attr("disabled", false);
      	                        	jQuery(".importPumpList").attr("disabled", false);
      	                        	jQuery(".addOtherBtn").attr("disabled", false);
      	      	            		jQuery(".importOtherList").attr("disabled", false);
      	                        	if (state=="addPumpBtn"){
      	                        		showDeviceModal();
      	                        	}else if(state=="importPumpList"){
      	                        		var type = '1';
      	                        		fileUpload(contractId, type);
      	                        	}
      	                        }
      	                    });
      	            }
      	    	});
      		}else{
      	            var url = window.rootPath + "/ui/contract/saveContract";
      	            jQuery.ajax({
      	                type: 'post',
      	                url: url,
      	                data: JSON.stringify(d),
      	                dataType: 'json',
      	                contentType: 'application/json;charset=utf-8',
      	                success: function (data) {
      	                	var contractId = data.contractId;
      	                	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
	                        jQuery("#createTime").val(time);
      	                	jQuery("#contractId").val(contractId);
      	                	jQuery(".addPumpBtn").attr("disabled", false);
      	                	jQuery(".importPumpList").attr("disabled", false);
      	                	jQuery(".addOtherBtn").attr("disabled", false);
      	            		jQuery(".importOtherList").attr("disabled", false);
	                        if (state=="addPumpBtn"){
	                       		showDeviceModal();
	                       	}else if(state=="importPumpList"){
  	                        	var type = '1';
  	                       		fileUpload(contractId, type);
  	                       	}
      	                }
      	            });
      		}
      	};
        
        /**
      	 * 添加泵时初始化弹窗
      	 */
        var showDeviceModal = function() {
        	var productType = jQuery("#productType :selected").text();
        	jQuery("#subDivideType").empty();
        	var url=window.rootPath+"/ui/contract/getDeviceOption/"+productType;
    		jQuery.ajax({
    			url:  encodeURI(url),
    			cache:false,
                type: 'get',
                dataType: 'json',
                success: function (data) {
                	var options = data.options;
                	for (var i=0; i<options.length; i++ ) 
                	{ 
                		var option = $("<option>").text(options[i]).val(options[i])
                	    jQuery("#subDivideType").append(option);
                	} 
                    jQuery("#mainDeviceId").val('');
                    jQuery("#maincreateTime").val('');
    				jQuery("#productName").val('');
    				jQuery("#productModel").val('');
    				jQuery("#number").val('');
    				jQuery("#unitPrice").val('');
    				jQuery("#power").val('');
    				jQuery("#viscosity").val('');
    				jQuery("#flowMaterial").val('');
    				jQuery("#transMedia").val('');
    				jQuery("#proportion").val('');
    				jQuery("#NPSHA").val('');
    				jQuery("#flux").val('');
    				jQuery("#temperature").val('');
    				jQuery("#MPSHA").val('');
    				jQuery("#pumpLift").val('');
    				jQuery("#inPressure").val('');
    				jQuery("#BillType").val('');
    				jQuery("#Motor").val('');
    				jQuery("#Attachment").val('');
    				jQuery("#SysPump").val('');
    				jQuery("#PumpType").val('');
    				jQuery("#PumpNum").val('');
    				jQuery("#PumpTotalPrice").val('');
    				jQuery("#dDeliveryDate").val('');
    				jQuery("#IsSpecial").val('');
    				jQuery("#Structure").val('');
    				jQuery("#OutletPressure").val('');
    				jQuery("#BitNumber").val('');
    				jQuery("#Unit").val('');
    				jQuery("#Memo").val('');
    				jQuery("#mainDeviceModal").modal('show');
                }
            });
        }
    	
    	/**
    	 * 文件上传插件
    	 */
    	var fileUpload = function(contractId, type) {
    		var root = window.rootPath;
    		WebFilesUploader(
    				{
    					_webuploader : {
    						server : root + '/ui/contract/import/' + contractId +'/'+ type,
    						swf : root
    								+ '/resources/poweradminjs/webupload/webfilesuploader/Uploader.swf',
    						chunked:false		
    					}
    				
    				}, function(jsons) {  			
    					contractPumpData.contractId=jQuery('#contractId').val();
    					serverPumpTable.draw(true);
    				});
           
    	
    	};
    	
    	//列表中的全选
        $("#checkAllPump").click(function(){
        	var check = $(this).prop("checked");
            $(".checkchildPump").prop("checked", check);
    	});
    	
    });
})();